package com.songlanyun.modules.offlinegoods.enums;

import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonCreator;

/**
 * 线下商品所属类型枚举 0商品 1服务
 *
 * @author lijiahe 2023-02-11
 */

public enum OfflineGoodsTypeEnum {

    /**
     * 商品
     */
    COMMODITY(0, "commodity"),

    /**
     * 服务
     */
    SERVICE(1, "service"),
    ;

    private Integer value;
    private String code;

    OfflineGoodsTypeEnum(Integer value, String code) {
        this.code = code;
        this.value = value;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @JsonCreator
    public static OfflineGoodsTypeEnum getByCode(String code) {
        for (OfflineGoodsTypeEnum e : OfflineGoodsTypeEnum.values()) {
            if (ObjectUtil.equal(code, e.getCode())){
                return e;
            }
        }
        return null;
    }
}
